from contextlib import contextmanager,nested


@contextmanager
def test():
    print("this is __enter__")
    yield "contextmanager demo"
    print("this is __exit__")


with test() as t:
    print(f"result: {t}")


with nested(A(),B(),C()) as (X,Y,Z):
    pass

with A() as X:
    pass
    with B() as Y:
        pass
        with C() as Z:
            pass


class closing(object):       
    def __init__(self, thing):        
        self.thing = thing    
    def __enter__(self):        
        return self.thing    
    def __exit__(self, *exc_info):        
        self.thing.close()




